<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of mandatos
 *
 * @author vitoco
 */
class mandatos {
    
    private $db = null;
    
    public function __construct($db) {
	if ($db !== null) $this->db = $db;
    }
    
    /**********
     * Para ver informacion
     */
    
    public function listaPendientes($filtro){
        if (!$this->db->Query("SELECT * FROM view_pendientes")){
            echo $this->db->Kill();
        }else{
            $arr = json_decode($this->db->GetJSON(),true);
            if(is_array($arr)){
                foreach ($resul as $row) {
                    
                }
            }
        }
    }
    
    public function listaEnviados($filtro){
        
    }
    
    public function listaActivos($filtro){
        
    }
    
    public function listaSinRespuesta($filtro){
        
    }
    
    public function listaFinalizados($filtro){
        
    }
    
    public function datosTitular(){
        
    }
    
    public function datosBeneficiario(){
        
    }
    
    public function verMandato(){
        
    }
    
    public function verCargosMandato(){
        
    }
    
    public function listaBanco(){
        if (!$this->db->Query("SELECT * FROM view_bancos")){
            echo $this->db->Kill();
        }
        else{
            $arr = json_decode($this->db->GetJSON(),true);
            if(is_array($arr)){
                foreach ($arr as $row) {
                    $resul .= '<option value="'.$row['ban_cod'].'">'.utf8_decode($row['ban_nom']).'</option>';
                }
                return $resul;
            }
        }
    }
    
    public function listaCobro(){
        if (!$this->db->Query("SELECT par_data FROM parametro WHERE par_cod = 'DIACOB'")){
            echo $this->db->Kill();
        }
        else{
            $arr = json_decode($this->db->GetJSON(),true);
            if(is_array($arr)){
                foreach ($arr as $row) {
                    $value = explode(",",$row['par_data']);
                    foreach($value as $dia){
                        $resul .= '<option value="'.$dia.'">'.$dia.'</option>';
                    }
                }
                return $resul;
            }
        }
    }
    
    /************
     * Acciones
     */
    
    public function nuevoMandato($datos){
        
        $arr = explode(";", $datos);
        foreach ($arr as $i => $value) {
            $arr[$i] = "'$value'";
        }
        
        if (!$this->db->Query("call sp_insert_mandato`(
                        $arr[0],
                        $arr[2],
                        $arr[1],
                        $arr[3],
                        $arr[4],
                        $arr[7],
                        $arr[5],
                        $arr[6],
                        $arr[8],
                        $arr[9])")){
            echo $this->db->Kill();
        }
        else{
        }
    }
    
    public function anularMandato(){
        
    }
    
    public function dejarPendientes(){
        
    }
    
    public function dejarPendiente(){
        
    }
    
    /********
     * Reportes
     */
    
    public function reporteEnviados(){
        
    }
    
}

?>
